from property import Property

class JsonProperty(Property):
    def __init__(self, **kwargs):
        kwargs['type'] = dict
        super(JsonProperty, self).__init__(**kwargs)
        
    def encode(self, v):
        if not isinstance(v, dict):
            raise ValueError("JsonProperty property %s value must be a dict. Got %s" % (self.get_id(), type(v)))
        return v
        
    def encode_repeated(self, v):
        for i, val in enumerate(v):
            if not isinstance(val, dict):
                raise ValueError("JsonProperty property %s value must be a list of dict. Got %s at %s" % (self.get_id(), type(val), i))
        return v

    def decode_single(self, v):
        return v
        
    def decode_repeated(self, v):
        return v
